#define quickread
#ifdef quickread
#include <cstdio> 
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}
template <typename T>
inline void quickwrite(T x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) quickwrite(x/10);
    putchar(x%10+'0');
}
#else 
#include <iostream>
#endif
const int INF=0x3f3f3f3f;
#include <cstring>
#include <functional>
using namespace std;
#define DEBUG
const int N=110, M=N<<1;

int graph[N][N];
int n, w[N];
int val, ans=INF;

void floyd()
{
    for(int k=1; k<=n; k++)
    {
        for(int i=1; i<=n; i++)
        {
            if(i==k) continue; //
            for(int j=1; j<=n; j++)
                if(i!=j&&k!=j&&graph[i][k]+graph[k][j]<graph[i][j]) //i,j中间必须要有节点
                    graph[i][j]=graph[i][k]+graph[k][j];
        }
    }
}

void init()
{
    read(n);
    memset(graph, 0x3f, sizeof graph); //所有点不可达

    for(int i=1; i<=n; i++)
    {
        graph[i][i]=0;
        int u, v;
        read(w[i]); read(u); read(v);
        if(u>0) graph[i][u]=graph[u][i]=1; //过1条边
        if(v>0) graph[i][v]=graph[v][i]=1;
    }
}

void solve()
{
    init();
    floyd();

    for(int i=1; i<=n; i++)
    {
        val=0;
        for(int j=1; j<=n; j++)
            val+=graph[i][j]*w[j];
        ans=min(ans, val);
    }
    quickwrite(ans); puts("");
}

// #undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
        // freopen("./out.txt", "w", stdout);
    #endif
    #ifndef quickread
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #endif

    int T=1; //scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}
